<script setup lang="ts">
const props = defineProps({
  visible: {
    type: Boolean,
    default: false,
  },
})

const emits = defineEmits(['update:visible', 'upload'])

const dialogVisible = ref(false)

watch(() => props.visible, (newVal) => {
  dialogVisible.value = newVal
})

function handleClose() {
  emits('update:visible', false)
}

function beforeUpload(file: File) {
  emits('upload', file)
  return false // 阻止默认上传行为
}
</script>

<template>
  <el-dialog v-model="dialogVisible" title="导入说明" width="400px" @close="handleClose">
    <ul>
      <li>✅ 支持文本文件（.txt）格式</li>
      <li>✅ 每行一个姓名</li>
      <li>🚫 不允许空行、重复或特殊字符</li>
      <li>
        ✅ 示例内容：
        <pre>张三<br>李四<br>王五<br></pre>
      </li>
    </ul>
    <template #footer>
      <div class="footer">
        <el-upload
          :show-file-list="false"
          accept=".txt"
          :before-upload="beforeUpload"
        >
          <el-button type="primary">
            选择文件导入
          </el-button>
        </el-upload>
        <el-button @click="handleClose">
          取消
        </el-button>
      </div>
    </template>
  </el-dialog>
</template>

<style lang="scss" scoped>
.footer {
  display: flex;
  justify-content: flex-end;
  gap: 12px;
  width: 100%;
}
</style>
